package com.java.base.exercise.current;

import java.util.concurrent.TimeUnit;

/**
 * @Author RenPu
 * @Date 2021/9/26 16:16
 * @Version 1.0
 * @Description:
 **/
public class DeadLocak {


    public static void main(String[] args) {

        Object key1 = new Object();
        Object key2 = new Object();

        new Thread(() -> {
            synchronized (key1) {
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (key2) {
                    System.out.println("thread-1,  获取到锁了  ！！！！！");
                }
            }
        }, "thread-1").start();


        new Thread(() -> {
            synchronized (key2) {
                synchronized (key1) {
                    System.out.println("thread-2,  获取到锁了  ！！！！！");
                }
            }
        }, "thread-2").start();


    }


}
